import { getDeptListApi } from '../../api/manage'
import create from 'dd-store'
import pageStore from '../../stores/globalStore'



create.Component({
  store: pageStore,
  mixins: [],
  data: {
    // 部门列表
    deptList: []
  },
  props: {},
  didMount() {
    // console.log(this.$store.data);
    this.getDetpListFunc()
  },
  didUpdate() { },
  didUnmount() { },
  methods: {
    // 部门点击事件
    deptItemClick(e) {
      let eItem = e.target.dataset.info
      console.log(eItem);
      dd.navigateTo({
        url: `/pages/manage/deptStaff/deptStaff?deptDDId=${eItem.deptDDId}&deptName=${eItem.deptName}`
      })
    },
    // 查询部门列表的函数
    getDetpListFunc() {
      dd.getStorage({
        key: 'currentCity',
        success: (res) => {
          let data = {
            userDDId: res.data.value.userId
          }
          dd.showLoading({
            content: "加载中"
          })
          getDeptListApi(data).then((res1) => {
            console.log('查询部门列表', res1);
            dd.hideLoading()
            let deptList = []
            if (res1.result == "success") {
              deptList = res1.data
            } else if (res1.status == 400) {
              deptList = []
            }
            this.setData({
              deptList: deptList
            })
          }).catch((err) => {
            dd.hideLoading()
          })
        },
        fail: function (res) {
          dd.alert({ content: res.errorMessage });
        }
      });

    }
  },
});
